home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / FLREAD.C < prev    next >
Text File  |  1990-08-09  |  2KB  |  60 lines

  1. /**
  2. *
  3. *  Name         flread -- Read from a file to a buffer
  4. *
  5. *  Synopsis     ercode = flread(handle,pbufads,nbytes,pnread);
  6. *               int  ercode       DOS function return error code
  7. *               int  handle       File handle
  8. *               ADS  *pbufads     Segment, offset address of input buffer
  9. *               unsigned nbytes   Number of bytes to read
  10. *               unsigned *pnread  Number of bytes actually returned
  11. *
  12. *  Description  flread transfers the specified number of bytes (nbytes)
  13. *               from the file (whose handle is specified) to a buffer whose
  14. *               segment and offset address is pointed to by pbufads.  The
  15. *               number of bytes actually read is also returned.  The file
  16. *               pointer is moved the number of bytes read; therefore,
  17. *               successive calls to flread will sequentially read the file.
  18. *
  19. *  Returns      ercode            DOS 2.0 function error code
  20. *               pnread            The number of bytes transferred to the
  21. *                                 I/O buffer.
  22. *
  23. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  24. *
  25. **/
  26. struct dreg
  27. {
  28.   unsigned ax,bx,cx,dx,si,di,ds,es;
  29. };
  30. #define DOSREG  struct dreg
  31.  
  32. struct segads                          /* Segment,offset address type  */
  33. {
  34.   unsigned r;
  35.   unsigned s;
  36. };
  37. #define ADS     struct segads          /* Abbreviation                 */
  38.  
  39. int flread(handle,pbufads,nbytes,pnread)
  40. int handle;
  41. ADS *pbufads;
  42. unsigned nbytes,*pnread;
  43. {
  44.  
  45.     DOSREG dos_reg;
  46.     int    ercode,utinit(),dos();
  47.  
  48.     utinit(&dos_reg);                  /* Initialize the registers     */
  49.     dos_reg.ax = 0x3f00;               /* DOS function 3F              */
  50.     dos_reg.bx = handle;
  51.     dos_reg.cx = nbytes;
  52.     dos_reg.dx = pbufads->r;
  53.     dos_reg.ds = pbufads->s;
  54.     ercode     = dos(&dos_reg);
  55.     *pnread    = dos_reg.ax;
  56.  
  57.     return(ercode);
  58.  
  59. }
  60.